package Lee_code;

import java.util.Arrays;

public class Lee_941 {
    public boolean validMountainArray(int[] arr) {
        int len = arr.length;
        if(len<=2)
            return false;
        int top = Arrays.stream(arr).max().getAsInt();
        int sign=0;
        for(int i=0 ;i<len ;i++) {
            if (arr[i]==top)
                sign = i;
        }

        if (sign==0||sign==len-1)
            return false;

        boolean up_way = true;
        boolean down_way = true;

        int temp = top;
        //下山的路
        for(int i=sign+1; i<len; i++)
        {
            if(temp<=arr[i]) {
                down_way = false;
                break;
            }
            temp=arr[i];
        }

        temp = top;
        //上山的路
        for(int i=sign-1; i>=0; i--)
        {
            if(temp<=arr[i]) {
                up_way = false;
                break;
            }
            temp=arr[i];
        }

        return up_way && down_way;
    }
}
